{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CSV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>23.53</td>\n",
       "      <td>25.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>22.80</td>\n",
       "      <td>23.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>22.88</td>\n",
       "      <td>23.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>22.25</td>\n",
       "      <td>22.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>21.49</td>\n",
       "      <td>21.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>13.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.67</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>643 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high\n",
       "2018-02-27  23.53  25.88\n",
       "2018-02-26  22.80  23.78\n",
       "2018-02-23  22.88  23.37\n",
       "2018-02-22  22.25  22.76\n",
       "2018-02-14  21.49  21.99\n",
       "...           ...    ...\n",
       "2015-03-06  13.17  14.48\n",
       "2015-03-05  12.88  13.45\n",
       "2015-03-04  12.80  12.92\n",
       "2015-03-03  12.52  13.06\n",
       "2015-03-02  12.25  12.67\n",
       "\n",
       "[643 rows x 2 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取，read_csv('文件路径', sep, usecols)，sep默认按逗号分隔，usecols是读取哪列数据\n",
    "data = pd.read_csv('./data/stock_day.csv', usecols=['open', 'high'])\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 写入，to_csv('路径', columns，index)，columns是指定存储哪列，index默认是True，表示存储索引，\n",
    "# 如果改为False，则不存储索引\n",
    "data.to_csv('./data/new_csv.csv', columns=['open'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# HDF5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>000001.SZ</th>\n",
       "      <th>000002.SZ</th>\n",
       "      <th>000004.SZ</th>\n",
       "      <th>000005.SZ</th>\n",
       "      <th>000006.SZ</th>\n",
       "      <th>000007.SZ</th>\n",
       "      <th>000008.SZ</th>\n",
       "      <th>000009.SZ</th>\n",
       "      <th>000010.SZ</th>\n",
       "      <th>000011.SZ</th>\n",
       "      <th>...</th>\n",
       "      <th>001965.SZ</th>\n",
       "      <th>603283.SH</th>\n",
       "      <th>002920.SZ</th>\n",
       "      <th>002921.SZ</th>\n",
       "      <th>300684.SZ</th>\n",
       "      <th>002922.SZ</th>\n",
       "      <th>300735.SZ</th>\n",
       "      <th>603329.SH</th>\n",
       "      <th>603655.SH</th>\n",
       "      <th>603080.SH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>16.30</td>\n",
       "      <td>17.71</td>\n",
       "      <td>4.58</td>\n",
       "      <td>2.88</td>\n",
       "      <td>14.60</td>\n",
       "      <td>2.62</td>\n",
       "      <td>4.96</td>\n",
       "      <td>4.66</td>\n",
       "      <td>5.37</td>\n",
       "      <td>6.02</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17.02</td>\n",
       "      <td>19.20</td>\n",
       "      <td>4.65</td>\n",
       "      <td>3.02</td>\n",
       "      <td>15.97</td>\n",
       "      <td>2.65</td>\n",
       "      <td>4.95</td>\n",
       "      <td>4.70</td>\n",
       "      <td>5.37</td>\n",
       "      <td>6.27</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>17.02</td>\n",
       "      <td>17.28</td>\n",
       "      <td>4.56</td>\n",
       "      <td>3.06</td>\n",
       "      <td>14.37</td>\n",
       "      <td>2.63</td>\n",
       "      <td>4.82</td>\n",
       "      <td>4.47</td>\n",
       "      <td>5.37</td>\n",
       "      <td>5.96</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>16.18</td>\n",
       "      <td>16.97</td>\n",
       "      <td>4.49</td>\n",
       "      <td>2.95</td>\n",
       "      <td>13.10</td>\n",
       "      <td>2.73</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.33</td>\n",
       "      <td>5.37</td>\n",
       "      <td>5.77</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16.95</td>\n",
       "      <td>17.19</td>\n",
       "      <td>4.55</td>\n",
       "      <td>2.99</td>\n",
       "      <td>13.18</td>\n",
       "      <td>2.77</td>\n",
       "      <td>4.97</td>\n",
       "      <td>4.42</td>\n",
       "      <td>5.37</td>\n",
       "      <td>5.92</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 3562 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   000001.SZ  000002.SZ  000004.SZ  000005.SZ  000006.SZ  000007.SZ  \\\n",
       "0      16.30      17.71       4.58       2.88      14.60       2.62   \n",
       "1      17.02      19.20       4.65       3.02      15.97       2.65   \n",
       "2      17.02      17.28       4.56       3.06      14.37       2.63   \n",
       "3      16.18      16.97       4.49       2.95      13.10       2.73   \n",
       "4      16.95      17.19       4.55       2.99      13.18       2.77   \n",
       "\n",
       "   000008.SZ  000009.SZ  000010.SZ  000011.SZ  ...  001965.SZ  603283.SH  \\\n",
       "0       4.96       4.66       5.37       6.02  ...        NaN        NaN   \n",
       "1       4.95       4.70       5.37       6.27  ...        NaN        NaN   \n",
       "2       4.82       4.47       5.37       5.96  ...        NaN        NaN   \n",
       "3       4.89       4.33       5.37       5.77  ...        NaN        NaN   \n",
       "4       4.97       4.42       5.37       5.92  ...        NaN        NaN   \n",
       "\n",
       "   002920.SZ  002921.SZ  300684.SZ  002922.SZ  300735.SZ  603329.SH  \\\n",
       "0        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "1        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "3        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "4        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "\n",
       "   603655.SH  603080.SH  \n",
       "0        NaN        NaN  \n",
       "1        NaN        NaN  \n",
       "2        NaN        NaN  \n",
       "3        NaN        NaN  \n",
       "4        NaN        NaN  \n",
       "\n",
       "[5 rows x 3562 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读文件read_hdf('路径', key)\n",
    "data = pd.read_hdf('./data/test_py38.h5')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存文件to_hdf('路径')\n",
    "data.to_hdf('./data/new_h5.h5', key='new_close')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>000001.SZ</th>\n",
       "      <th>000002.SZ</th>\n",
       "      <th>000004.SZ</th>\n",
       "      <th>000005.SZ</th>\n",
       "      <th>000006.SZ</th>\n",
       "      <th>000007.SZ</th>\n",
       "      <th>000008.SZ</th>\n",
       "      <th>000009.SZ</th>\n",
       "      <th>000010.SZ</th>\n",
       "      <th>000011.SZ</th>\n",
       "      <th>...</th>\n",
       "      <th>001965.SZ</th>\n",
       "      <th>603283.SH</th>\n",
       "      <th>002920.SZ</th>\n",
       "      <th>002921.SZ</th>\n",
       "      <th>300684.SZ</th>\n",
       "      <th>002922.SZ</th>\n",
       "      <th>300735.SZ</th>\n",
       "      <th>603329.SH</th>\n",
       "      <th>603655.SH</th>\n",
       "      <th>603080.SH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>16.30</td>\n",
       "      <td>17.71</td>\n",
       "      <td>4.58</td>\n",
       "      <td>2.88</td>\n",
       "      <td>14.60</td>\n",
       "      <td>2.62</td>\n",
       "      <td>4.96</td>\n",
       "      <td>4.66</td>\n",
       "      <td>5.37</td>\n",
       "      <td>6.02</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17.02</td>\n",
       "      <td>19.20</td>\n",
       "      <td>4.65</td>\n",
       "      <td>3.02</td>\n",
       "      <td>15.97</td>\n",
       "      <td>2.65</td>\n",
       "      <td>4.95</td>\n",
       "      <td>4.70</td>\n",
       "      <td>5.37</td>\n",
       "      <td>6.27</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>17.02</td>\n",
       "      <td>17.28</td>\n",
       "      <td>4.56</td>\n",
       "      <td>3.06</td>\n",
       "      <td>14.37</td>\n",
       "      <td>2.63</td>\n",
       "      <td>4.82</td>\n",
       "      <td>4.47</td>\n",
       "      <td>5.37</td>\n",
       "      <td>5.96</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>16.18</td>\n",
       "      <td>16.97</td>\n",
       "      <td>4.49</td>\n",
       "      <td>2.95</td>\n",
       "      <td>13.10</td>\n",
       "      <td>2.73</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.33</td>\n",
       "      <td>5.37</td>\n",
       "      <td>5.77</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>16.95</td>\n",
       "      <td>17.19</td>\n",
       "      <td>4.55</td>\n",
       "      <td>2.99</td>\n",
       "      <td>13.18</td>\n",
       "      <td>2.77</td>\n",
       "      <td>4.97</td>\n",
       "      <td>4.42</td>\n",
       "      <td>5.37</td>\n",
       "      <td>5.92</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2673</th>\n",
       "      <td>12.96</td>\n",
       "      <td>35.99</td>\n",
       "      <td>22.84</td>\n",
       "      <td>4.37</td>\n",
       "      <td>9.85</td>\n",
       "      <td>16.66</td>\n",
       "      <td>8.47</td>\n",
       "      <td>7.52</td>\n",
       "      <td>6.20</td>\n",
       "      <td>17.88</td>\n",
       "      <td>...</td>\n",
       "      <td>12.99</td>\n",
       "      <td>23.42</td>\n",
       "      <td>47.99</td>\n",
       "      <td>32.40</td>\n",
       "      <td>22.45</td>\n",
       "      <td>28.79</td>\n",
       "      <td>23.18</td>\n",
       "      <td>24.45</td>\n",
       "      <td>14.98</td>\n",
       "      <td>26.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2674</th>\n",
       "      <td>13.08</td>\n",
       "      <td>35.84</td>\n",
       "      <td>23.02</td>\n",
       "      <td>4.41</td>\n",
       "      <td>9.85</td>\n",
       "      <td>16.66</td>\n",
       "      <td>8.49</td>\n",
       "      <td>7.48</td>\n",
       "      <td>6.01</td>\n",
       "      <td>17.75</td>\n",
       "      <td>...</td>\n",
       "      <td>12.83</td>\n",
       "      <td>25.76</td>\n",
       "      <td>45.14</td>\n",
       "      <td>35.64</td>\n",
       "      <td>24.70</td>\n",
       "      <td>31.67</td>\n",
       "      <td>25.50</td>\n",
       "      <td>26.90</td>\n",
       "      <td>16.48</td>\n",
       "      <td>28.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2675</th>\n",
       "      <td>13.47</td>\n",
       "      <td>35.67</td>\n",
       "      <td>22.40</td>\n",
       "      <td>4.32</td>\n",
       "      <td>9.85</td>\n",
       "      <td>16.66</td>\n",
       "      <td>8.49</td>\n",
       "      <td>7.38</td>\n",
       "      <td>5.97</td>\n",
       "      <td>17.45</td>\n",
       "      <td>...</td>\n",
       "      <td>12.20</td>\n",
       "      <td>28.34</td>\n",
       "      <td>43.21</td>\n",
       "      <td>39.20</td>\n",
       "      <td>27.17</td>\n",
       "      <td>34.84</td>\n",
       "      <td>28.05</td>\n",
       "      <td>29.59</td>\n",
       "      <td>18.13</td>\n",
       "      <td>31.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2676</th>\n",
       "      <td>13.40</td>\n",
       "      <td>35.15</td>\n",
       "      <td>22.29</td>\n",
       "      <td>4.29</td>\n",
       "      <td>9.85</td>\n",
       "      <td>16.66</td>\n",
       "      <td>8.56</td>\n",
       "      <td>7.04</td>\n",
       "      <td>5.84</td>\n",
       "      <td>17.49</td>\n",
       "      <td>...</td>\n",
       "      <td>12.11</td>\n",
       "      <td>31.17</td>\n",
       "      <td>43.76</td>\n",
       "      <td>40.88</td>\n",
       "      <td>29.89</td>\n",
       "      <td>34.84</td>\n",
       "      <td>29.64</td>\n",
       "      <td>32.55</td>\n",
       "      <td>19.94</td>\n",
       "      <td>34.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2677</th>\n",
       "      <td>13.55</td>\n",
       "      <td>35.55</td>\n",
       "      <td>22.20</td>\n",
       "      <td>4.37</td>\n",
       "      <td>9.85</td>\n",
       "      <td>16.66</td>\n",
       "      <td>8.67</td>\n",
       "      <td>7.06</td>\n",
       "      <td>5.99</td>\n",
       "      <td>17.76</td>\n",
       "      <td>...</td>\n",
       "      <td>11.91</td>\n",
       "      <td>34.29</td>\n",
       "      <td>41.71</td>\n",
       "      <td>39.10</td>\n",
       "      <td>32.88</td>\n",
       "      <td>34.84</td>\n",
       "      <td>27.92</td>\n",
       "      <td>31.82</td>\n",
       "      <td>21.93</td>\n",
       "      <td>38.16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2678 rows × 3562 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      000001.SZ  000002.SZ  000004.SZ  000005.SZ  000006.SZ  000007.SZ  \\\n",
       "0         16.30      17.71       4.58       2.88      14.60       2.62   \n",
       "1         17.02      19.20       4.65       3.02      15.97       2.65   \n",
       "2         17.02      17.28       4.56       3.06      14.37       2.63   \n",
       "3         16.18      16.97       4.49       2.95      13.10       2.73   \n",
       "4         16.95      17.19       4.55       2.99      13.18       2.77   \n",
       "...         ...        ...        ...        ...        ...        ...   \n",
       "2673      12.96      35.99      22.84       4.37       9.85      16.66   \n",
       "2674      13.08      35.84      23.02       4.41       9.85      16.66   \n",
       "2675      13.47      35.67      22.40       4.32       9.85      16.66   \n",
       "2676      13.40      35.15      22.29       4.29       9.85      16.66   \n",
       "2677      13.55      35.55      22.20       4.37       9.85      16.66   \n",
       "\n",
       "      000008.SZ  000009.SZ  000010.SZ  000011.SZ  ...  001965.SZ  603283.SH  \\\n",
       "0          4.96       4.66       5.37       6.02  ...        NaN        NaN   \n",
       "1          4.95       4.70       5.37       6.27  ...        NaN        NaN   \n",
       "2          4.82       4.47       5.37       5.96  ...        NaN        NaN   \n",
       "3          4.89       4.33       5.37       5.77  ...        NaN        NaN   \n",
       "4          4.97       4.42       5.37       5.92  ...        NaN        NaN   \n",
       "...         ...        ...        ...        ...  ...        ...        ...   \n",
       "2673       8.47       7.52       6.20      17.88  ...      12.99      23.42   \n",
       "2674       8.49       7.48       6.01      17.75  ...      12.83      25.76   \n",
       "2675       8.49       7.38       5.97      17.45  ...      12.20      28.34   \n",
       "2676       8.56       7.04       5.84      17.49  ...      12.11      31.17   \n",
       "2677       8.67       7.06       5.99      17.76  ...      11.91      34.29   \n",
       "\n",
       "      002920.SZ  002921.SZ  300684.SZ  002922.SZ  300735.SZ  603329.SH  \\\n",
       "0           NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "1           NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2           NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "3           NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "4           NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "...         ...        ...        ...        ...        ...        ...   \n",
       "2673      47.99      32.40      22.45      28.79      23.18      24.45   \n",
       "2674      45.14      35.64      24.70      31.67      25.50      26.90   \n",
       "2675      43.21      39.20      27.17      34.84      28.05      29.59   \n",
       "2676      43.76      40.88      29.89      34.84      29.64      32.55   \n",
       "2677      41.71      39.10      32.88      34.84      27.92      31.82   \n",
       "\n",
       "      603655.SH  603080.SH  \n",
       "0           NaN        NaN  \n",
       "1           NaN        NaN  \n",
       "2           NaN        NaN  \n",
       "3           NaN        NaN  \n",
       "4           NaN        NaN  \n",
       "...         ...        ...  \n",
       "2673      14.98      26.06  \n",
       "2674      16.48      28.67  \n",
       "2675      18.13      31.54  \n",
       "2676      19.94      34.69  \n",
       "2677      21.93      38.16  \n",
       "\n",
       "[2678 rows x 3562 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取保存的文件，检验保存，文件时直接打开的话显示不了数据，只能靠代码读取，\n",
    "# key相当于在保存文件后生成的一个钥匙，当读取这个文件时得用生成的这个要是打开才能读取。\n",
    "save_data = pd.read_hdf('./data/new_h5.h5', key='new_close')\n",
    "save_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# JSON"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>article_link</th>\n",
       "      <th>headline</th>\n",
       "      <th>is_sarcastic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/versace-b...</td>\n",
       "      <td>former versace store clerk sues over secret 'b...</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/roseanne-...</td>\n",
       "      <td>the 'roseanne' revival catches up to our thorn...</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>https://local.theonion.com/mom-starting-to-fea...</td>\n",
       "      <td>mom starting to fear son's web series closest ...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>https://politics.theonion.com/boehner-just-wan...</td>\n",
       "      <td>boehner just wants wife to listen, not come up...</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/jk-rowlin...</td>\n",
       "      <td>j.k. rowling wishes snape happy birthday in th...</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26704</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/american-...</td>\n",
       "      <td>american politics in moral free-fall</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26705</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/americas-...</td>\n",
       "      <td>america's best 20 hikes</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26706</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/reparatio...</td>\n",
       "      <td>reparations and obama</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26707</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/israeli-b...</td>\n",
       "      <td>israeli ban targeting boycott supporters raise...</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26708</th>\n",
       "      <td>https://www.huffingtonpost.com/entry/gourmet-g...</td>\n",
       "      <td>gourmet gifts for the foodie 2014</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>26709 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            article_link  \\\n",
       "0      https://www.huffingtonpost.com/entry/versace-b...   \n",
       "1      https://www.huffingtonpost.com/entry/roseanne-...   \n",
       "2      https://local.theonion.com/mom-starting-to-fea...   \n",
       "3      https://politics.theonion.com/boehner-just-wan...   \n",
       "4      https://www.huffingtonpost.com/entry/jk-rowlin...   \n",
       "...                                                  ...   \n",
       "26704  https://www.huffingtonpost.com/entry/american-...   \n",
       "26705  https://www.huffingtonpost.com/entry/americas-...   \n",
       "26706  https://www.huffingtonpost.com/entry/reparatio...   \n",
       "26707  https://www.huffingtonpost.com/entry/israeli-b...   \n",
       "26708  https://www.huffingtonpost.com/entry/gourmet-g...   \n",
       "\n",
       "                                                headline  is_sarcastic  \n",
       "0      former versace store clerk sues over secret 'b...             0  \n",
       "1      the 'roseanne' revival catches up to our thorn...             0  \n",
       "2      mom starting to fear son's web series closest ...             1  \n",
       "3      boehner just wants wife to listen, not come up...             1  \n",
       "4      j.k. rowling wishes snape happy birthday in th...             0  \n",
       "...                                                  ...           ...  \n",
       "26704               american politics in moral free-fall             0  \n",
       "26705                            america's best 20 hikes             0  \n",
       "26706                              reparations and obama             0  \n",
       "26707  israeli ban targeting boycott supporters raise...             0  \n",
       "26708                  gourmet gifts for the foodie 2014             0  \n",
       "\n",
       "[26709 rows x 3 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取json数据read_json('路径',orient, lines, typ)，orient是按什么样的形式输出，\n",
    "# lines是否按照每行读取json数据，typ指定转换类型对象是series还是dataframe，默认是dataframe\n",
    "data = pd.read_json('./data/test_py38.json', orient='records', lines=True, typ='frame')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存，to_json('路径', orient, lines)，lines=True的话，存储到文件中的数据有行号显示，\n",
    "# 那么读文件时也必须指明lines为True\n",
    "data.to_json('./data/new_json.json', orient='records', lines=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
